'use strict';

const db = uniCloud.database()
const bannersCollection = db.collection('banners')

exports.main = async (event, context) => {
	try {
		const { bannerId } = event
		
		if (!bannerId) {
			return {
				code: -1,
				msg: '轮播图ID不能为空',
				data: null
			}
		}
		
		// 检查轮播图是否存在
		const banner = await bannersCollection.doc(bannerId).get()
		if (banner.data.length === 0) {
			return {
				code: -1,
				msg: '轮播图不存在',
				data: null
			}
		}
		
		// 删除轮播图
		await bannersCollection.doc(bannerId).remove()
		
		return {
			code: 0,
			msg: '删除成功',
			data: null
		}
	} catch (error) {
		console.error('删除轮播图失败', error)
		return {
			code: -1,
			msg: '删除失败',
			data: null
		}
	}
} 